

#  激活函数

#  跃阶函数图形

import numpy as np

import matplotlib.pyplot as plt
from matplotlib.lines import lineStyles


def step_function(x):
    return np.array(x>0, dtype=int)

x = np.arange(-5.0,5.0,0.1)
y1= step_function (x)
plt.plot(x,y1,linestyle='--')

plt.ylim(-0.1,1.1)

# plt.show()


#  sigmoid 函数实现

def sigmoid(x):
    return 1/(1+np.exp(-x))

# x=np.array([-1.0,1.0,2.0])
# print(sigmoid(x))

x=np.arange(-5.0,5.0,0.1)

y2=sigmoid(x)
plt.plot(x,y2)

plt.ylim(-0.1,1.1)

plt.show()



#  ReLU  激活函数

def ReLU(x):
    return np.maximum(0,x)

x = np.arange(-5.0,5.0,0.1)

y3=ReLU(x)
plt.plot(x,y3)
# plt.ylim(-0.1,1.1)

plt.show()



